﻿#include <QCoreApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>

#include "g_ver.h"
#include "analyzer.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    a.setApplicationName(SP_NAME);
    a.setApplicationVersion(SP_VERSION);

    QCommandLineParser parser;
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addPositionalArgument("input","Video File");

    QCommandLineOption writeOption(QStringList() << "w" << "write","write to file");
    parser.addOption(writeOption);
    parser.process(a);

    const QStringList args=parser.positionalArguments();
    if(args.isEmpty())
    {
        qDebug() << "missing parameter";
        return 0;
    }

    QString filePath=args.first();
    Analyzer analyzer(filePath);
    if(!analyzer.open())
    {
        qDebug() << "error: can't open file!";
        return 0;
    }

    if(parser.isSet(writeOption))
        analyzer.writeVideoInfo();
    else
        analyzer.printVideoInfo();

    return 0;
}
